package book.BouncySquare;

import android.content.Context;
import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.MotionEvent;

public class BouncyView extends GLSurfaceView
{

    public SquareRenderer mRenderer;

    private float mPreviousX = 0.0f;

    private float mPreviousY = 0.0f;

    public BouncyView(Context context)
    {
	super(context);

	mRenderer = new SquareRenderer(true);
	setRenderer(mRenderer);
    }

    public boolean onTouchEvent(MotionEvent e)
    {
	/*
	 * switch (ev.getAction() & MotionEvent.ACTION_MASK) { case
	 * MotionEvent.ACTION_DOWN: ((SquareRenderer)
	 * mRenderer).setmTranslucentBackground(false); break; } return true;
	 */

	float x = e.getX();
	float y = e.getY();

	switch (e.getAction())
	{
	    case MotionEvent.ACTION_DOWN:
		Log.d("Event", "Down");
		break;
		
	    case MotionEvent.ACTION_MOVE:

		float dx = x - mPreviousX;
		float dy = y - mPreviousY;

		/*
		 * if (y > getHeight() / 2) { dx = dx * -1; } if (x < getWidth()
		 * / 2) { dy = dy * -1; }
		 */

		mRenderer.setmTargetAngle(mRenderer.getmTargetAngle() + (((dy)) * (180.0f / 320.0f)));
		mRenderer.setmTargetZ(mRenderer.getmTargetZ() + (((dx)) * (3.0f / 320.0f)));
		requestRender();

	}
	mPreviousX = x;
	mPreviousY = y;
	return true;

    }

}
